<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<input type="hidden" id="currentId" value="${productOrder.id}"><%--主订单id--%>
<%--更改办理渠道--%>
<div class="dialog-warp-ajax">
    <input type="hidden" id="productOrderIdAdd" value="${productOrder.id}"><%--主订单id--%>
    <table class="dggui-table-info">
        <tbody>
        <tr>
            <th><span class="required">业务类型：</span></th>
            <td id="typeCodeAddTip">
                <div name="typeCodeAdd" id="typeCodeAdd" data-code="${productOrder.businessProductCode}"
                     data-name="${productOrder.businessProductName}"></div>
            </td>
        </tr>
        <tr>
            <th><span class="required">产品：</span></th>
            <td id="productCodeAddTip">
                <select class="dggui-select" name="productCodeAdd" id="productCodeAdd"
                        data-code="${productOrder.productId}" data-name="${productOrder.productName}">
                    <option value="${productOrder.productId}" selected="selected">${productOrder.productName}</option>
                </select>
            </td>
        </tr>
      <%--  <tr>
            <th><span class="required">商品属性：</span></th>
            <td id="goodAttributeIdAddTip">
                <select class="dggui-select" name="goodAttributeIdAdd" id="goodAttributeIdAdd"
                        data-code="${productOrder.goodsId}" data-name="${productOrder.goodsName}">
                    <option value="">请选择</option>
                </select>
            </td>
        </tr>--%>

        <tr>
            <th><span class="required">渠道：</span></th>
            <td id="channelTip">
                <select class="dggui-select" name="channelAdd" id="channelAdd"
                        data-code="${productOrder.channelId}" data-name="${productOrder.channelName}">
                    <option value="">请选择</option>
                </select>
            </td>
        </tr>
        <tr>
            <th>支行：</th>
            <td>
                <input type="text" name="channelSubBranchAdd" maxlength="50" id="channelSubBranchAdd" class="dggui-input" value="${productOrder.subBranch}"/>
            </td>
        </tr>
        <tr>
            <th>服务合同编号：</th>
            <td>
                <input type="text" disabled="true" name="contractNoAdd" id="contractNoAdd" value="${productOrder.contractNo}"
                       class="dggui-input"/>
            </td>
        </tr>
        </tbody>
    </table>
</div>


<script type="text/javascript">

    $(function () {
        $(document).ready(function () {
            dggui.use(['select2', 'distpicker'], function () {
                var select2 = dggui.select2;
                var distpicker = dggui.distpicker;
                var businessProductName = $("#typeCodeAdd").attr("data-name");
                var businessProductCode = $("#typeCodeAdd").attr("data-code");
                var productId = $("#productCodeAdd").attr("data-code");
                var channelId= $("#channelAdd").attr("data-code");
                //var goodsId = $("#goodAttributeIdAdd").attr("data-code");

                distpicker.render({
                    url: "${basePath}/rzsc/common/tree_book_list.do?code=BUS_YT_DK&type=2&level=2", // 请求地址
                    elem: '#typeCodeAdd', // 容器Id
                    type: 2,
                    placeholder: "请选择业态",
                    defaultParentCode: 'BUS_YT_DK',
                    callback: function () {//如果不需要选产品就把callback整个方法注释掉
                        var code = $("#typeCodeAdd .plug-in-code").val();
                        initProductCode("#productCodeAdd", code);
                        select2.render({
                            placeholder: "请选择",
                            allowClear: true,
                            elem: $('#productCodeAdd'),
                        });
                        $("#channelAdd").find("option").remove();
                        $("#channelAdd").append("<option value=''>请选择</option>");
                       /* $("#goodAttributeIdAdd").find("option").remove();
                        $("#goodAttributeIdAdd").append("<option value=''>请选择</option>");*/
                    },
                    callbackClear: function () {
                        var currCode = $("#typeCodeAdd").attr("data-code");
                        initProductCode("#productCodeAdd", currCode);
                        select2.render({
                            placeholder: "请选择",
                            allowClear: true,
                            elem: $('#productCodeAdd'),
                        });
                        $("#productCodeAdd").find("option").remove();
                        $("#productCodeAdd").append("<option value=''>请选择</option>");
                        $("#channelAdd").find("option").remove();
                        $("#channelAdd").append("<option value=''>请选择</option>");
                        /*$("#goodAttributeIdAdd").find("option").remove();
                        $("#goodAttributeIdAdd").append("<option value=''>请选择</option>");*/
                    },
                });
                $("#typeCodeAdd .chose-plugIn").val(businessProductName);
                $("#typeCodeAdd .plug-in-code").val(businessProductCode);
                initProductCodeWithCode("#productCodeAdd", businessProductCode,productId);
                select2.render({
                    placeholder: "请选择",
                    allowClear: true,//清空选中
                    elem: $('#productCodeAdd'),
                    multiple: false,// 单选false或不写该参数，多选true
                });
                //加载商品下拉框
               /* initProductInfo("#goodAttributeIdAdd", productId,goodsId);
                select2.render({
                    placeholder: "请选择",
                    allowClear: true,
                    elem: $('#goodAttributeIdAdd'),
                });*/
                initChannel("#channelAdd",productId,channelId);
                select2.render({
                    placeholder: "请选择",
                    allowClear: true,
                    elem: $('#channelAdd'),
                });
                //商品选择弹窗入口
                // $("#goodAttributeIdAdd").click(function () {
                //     var typeParams=distpicker.getSelectOption({
                //         elem: $('#typeCodeAdd'),
                //         // 1只获取中文参数（默认），2获取所有参数
                //         type:2
                //     });
                //     var businessProductName = typeParams[0].text;
                //     var productName = $("#productCodeAdd option:selected").text();///产品名称
                //     var choosedProduct =businessProductName+"/"+productName;
                //     var goodId = $("#goodAttributeIdAdd").attr("data-id");
                //     var productId = $("#productCodeAdd").val();
                //     if (checkIsEmpty(productId)) {
                //         dggui.dialog.loading('close');
                //         dggui.dialog.errors("产品ID为空");
                //         return;
                //     };
                //     var params = new Object();
                //     params.productId = productId;
                //     params.choosedProduct = choosedProduct;
                //     params.goodId = goodId;
                //     initProductInfoDialog(params, '#goodAttributeIdAdd','#channelAdd');
                //
                // })
            });
        });

    });
    $('#productCodeAdd').on('change', function (e) {
        dggui.use(['select2'], function () {
            var select2 = dggui.select2;
            var productId = $("#productCodeAdd").val();
            $("#channelAdd").find("option").remove();
            $("#channelAdd").append("<option value=''>请选择</option>");
            //加载商品下拉框
           /* initProductInfo("#goodAttributeIdAdd", productId,null);
            select2.render({
                placeholder: "请选择",
                allowClear: true,
                elem: $('#goodAttributeIdAdd'),
            });*/
            initChannelWithCode("#channelAdd",productId,null);
            select2.render({
                placeholder: "请选择",
                allowClear: true,
                elem: $('#channelAdd'),
            });
        })
    });

/*    $('#goodAttributeIdAdd').on('change', function (e) {
        dggui.use(['select2'], function () {
            var select2 = dggui.select2;
            var productId = $("#productCodeAdd").val();
            initChannelWithCode("#channelAdd",productId,null);
            select2.render({
                placeholder: "请选择",
                allowClear: true,
                elem: $('#channelAdd'),
            });
        })

    });*/
</script>

